@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

:root {
  --bg-gradient: #ffffff !important;
  --card-bg: #ffffff;
  --accent: #667eea;
  --accent-dark: #5568d3;
  --accent-light: #f0f4ff;
  --primary: #764ba2;
  --primary-soft: #f5f3ff;
  --border: #e2e8f0;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.16);
  --font-main: 'Poppins', system-ui, -apple-system, sans-serif;
  --text-main: #000000;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Global reset */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Prevent horizontal scroll on mobile */
html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  min-height: 100vh;
}

body {
  font-family: var(--font-main);
  background: #ffffff; /* kept your change from var(--bg-gradient) */
  color: var(--text-main);
  line-height: 1.6;
  padding: 20px;
}

/* Main app wrapper */
.app {
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}

/* Header */
.page-header {
  text-align: center;
  margin-bottom: 24px;
  animation: fadeInDown 0.6s ease;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.page-brand h1 {
  font-size: 32px;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 8px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

.page-subtitle {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.9);
  font-weight: 400;
}

/* Language Switcher */
.header-right {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

.lang-switcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-md);
  transition: var(--transition);
}

.lang-switcher:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.lang-icon {
  font-size: 20px;
}

#lang-select {
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  outline: none;
  color: var(--text-main);
  cursor: pointer;
  font-family: var(--font-main);
}

/* Calculator Card */
.calc-card {
  background: var(--card-bg);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: fadeInUp 0.6s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.calc-header {
  padding: 20px;
  background: linear-gradient(135deg, var(--accent-light) 0%, #ffffff 100%);
}

.calc-display {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.3);
}

.calc-display-main {
  font-size: 48px;
  font-weight: 700;
  text-align: right;
  color: #ffffff;
  margin-bottom: 8px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  word-break: break-all;
}

.calc-display-sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.85);
  font-weight: 500;
}

.calc-display-sub span:last-child {
  font-family: 'Courier New', monospace;
  font-weight: 600;
}

/* Calc Body */
.calc-body {
  padding: 20px;
}

/* Keypad */
.keypad {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.key {
  border-radius: var(--radius-md);
  border: 2px solid var(--border);
  background: #ffffff;
  font-size: 20px;
  font-weight: 600;
  padding: 18px 0;
  min-height: 56px; /* better tap target */
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-main);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.key:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.key:active {
  transform: scale(0.95);
}

.key-operator {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-color: var(--accent-dark);
  color: #ffffff;
  font-weight: 700;
}

.key-operator:hover {
  background: linear-gradient(135deg, #5568d3 0%, #6a3f8f 100%);
  transform: translateY(-2px) scale(1.05);
}

.key-func {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  border-color: #f5576c;
  color: #ffffff;
  font-weight: 700;
}

.key-func:hover {
  background: linear-gradient(135deg, #e082ea 0%, #e4465b 100%);
  transform: translateY(-2px) scale(1.05);
}

.key-equal {
  grid-row: span 2;
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  border-color: #38f9d7;
  color: #000000;
  font-size: 28px;
  font-weight: 700;
}

.key-equal:hover {
  background: linear-gradient(135deg, #32d86b 0%, #27e8c6 100%);
  transform: translateY(-2px) scale(1.05);
}

/* Tabs */
.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 20px;
}

.tab {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  border: 2px solid var(--border);
  background: #ffffff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-main);
  color: var(--text-main);
  text-align: center;
}

.tab:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.tab.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #ffffff;
  border-color: var(--accent-dark);
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
}

/* Tab Content */
.tab-content {
  display: none;
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.tab-content.active {
  display: block;
}

.tab-text {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-weight: 400;
  line-height: 1.5;
}

/* Options */
.options-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.input {
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  font-family: var(--font-main);
  font-weight: 500;
  color: var(--text-main);
  transition: var(--transition);
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Buttons */
.btn-primary,
.btn-secondary {
  border-radius: var(--radius-lg);
  border: none;
  padding: 14px 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-main);
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #ffffff;
}

.btn-primary:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: #f8fafc;
  color: var(--text-main);
  border: 2px solid var(--border);
}

.btn-secondary:hover {
  background: var(--accent-light);
  border-color: var(--accent);
}

/* Result Box */
.result-box {
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--primary-soft);
  border: 2px dashed var(--accent);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-main);
  margin-bottom: 16px;
  text-align: center;
}

.result-box:hover {
  background: var(--accent-light);
  border-color: var(--accent-dark);
  transform: scale(1.02);
}

/* History */
.history-header {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

#history-list {
  list-style: none;
  font-size: 12px;
  max-height: 200px;
  overflow-y: auto;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  padding: 8px;
}

#history-list::-webkit-scrollbar {
  width: 6px;
}

#history-list::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 3px;
}

#history-list::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 3px;
}

#history-list li {
  padding: 6px 8px;
  color: var(--text-muted);
  border-bottom: 1px solid #e2e8f0;
  font-weight: 400;
}

#history-list li:last-child {
  border-bottom: none;
}

/* Toast */
#copy-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  background: var(--text-main);
  color: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: var(--transition);
  font-family: var(--font-main);
  z-index: 50;
}

#copy-toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* =========================
   Responsive Enhancements
   ========================= */

/* Tablets & small laptops */
@media (max-width: 768px) {
  body {
    padding: 16px;
  }

  .page-brand h1 {
    font-size: 26px;
  }

  .calc-card {
    border-radius: var(--radius-lg);
  }

  .calc-header,
  .calc-body {
    padding: 16px;
  }

  .calc-display-main {
    font-size: 40px;
  }

  .keypad {
    gap: 8px;
  }

  .key {
    font-size: 18px;
    padding: 16px 0;
  }

  .tabs {
    gap: 6px;
  }

  .tab {
    padding: 10px 12px;
    font-size: 12px;
  }
}

/* Phones */
@media (max-width: 600px) {
  body {
    padding: 12px;
  }

  .app {
    max-width: 100%;
  }

  .page-header {
    margin-bottom: 16px;
  }

  .page-brand h1 {
    font-size: 24px;
  }

  .page-subtitle {
    font-size: 12px;
  }

  .lang-switcher {
    padding: 8px 12px;
    box-shadow: var(--shadow-sm);
  }

  .calc-card {
    box-shadow: var(--shadow-md);
  }

  .calc-display {
    padding: 16px;
  }

  .calc-display-main {
    font-size: 32px;
  }

  .calc-display-sub {
    font-size: 12px;
  }

  .calc-body {
    padding: 16px 12px 18px;
  }

  /* Keep 5 columns but make them flexible and tall for touch */
  .keypad {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
  }

  .key {
    padding: 14px 0;
    min-height: 52px;
    font-size: 17px;
  }

  .tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .tab {
    padding: 9px 10px;
    font-size: 11px;
  }

  .options-grid {
    grid-template-columns: 1fr;
  }

  .btn-primary,
  .btn-secondary {
    padding: 12px 18px;
    font-size: 13px;
  }

  .result-box {
    font-size: 13px;
    padding: 14px;
  }

  #copy-toast {
    bottom: 16px;
    right: 16px;
    font-size: 13px;
    padding: 10px 16px;
  }
}

/* Extra-small phones */
@media (max-width: 400px) {
  .page-brand h1 {
    font-size: 20px;
  }

  .calc-display-main {
    font-size: 28px;
  }

  .keypad {
    gap: 6px;
  }

  .key {
    font-size: 16px;
    padding: 12px 0;
    min-height: 48px;
  }

  .tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* RTL Support for Arabic */
[dir="rtl"] {
  direction: rtl;
}

[dir="rtl"] .calc-display-main {
  text-align: left;
}

[dir="rtl"] .calc-display-sub {
  flex-direction: row-reverse;
}